﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace AirWar
{
   public class Map
    {
        //地图的图片
        private Bitmap _mapBitmap;
        //地图的尺寸大小
        private Size _size;
        //两幅地图的左上角的Y坐标
        private int _map1LeftTopY;
        private int _map2LeftTopY;

        public Size _Size { get => _size; set => _size = value; }
        //构造方法
        public Map(String BitmapFile)
        {
            //装载对应的地图文件
            _mapBitmap = new Bitmap(BitmapFile);
            _size = new Size(_mapBitmap.Width, _mapBitmap.Height);
            //让两幅地图竖着靠在一起
            _map1LeftTopY = -_size.Height;
            _map2LeftTopY = 0;
        }
        public void Scroll(int ScrollStep)
        {
            //让两幅地图向下滚动一段距离
            _map1LeftTopY = _map1LeftTopY + ScrollStep;
            _map2LeftTopY = _map2LeftTopY + ScrollStep;
            //如果超过了地图的高度，则回到顶部再开始滚动
            if (_map1LeftTopY >= _size.Height)
                _map1LeftTopY = -_size.Height;
            if (_map2LeftTopY >= _size.Height)
                _map2LeftTopY = -_size.Height;
        }
        //(方法)地图绘制
        public void DrawMe(Graphics g)
        {
            //绘制第一幅地图
            g.DrawImage(_mapBitmap, 0, _map1LeftTopY, _size.Width, _size.Height);
            //绘制第二幅地图(两幅地图刚好靠在一起)
            g.DrawImage(_mapBitmap, 0, _map2LeftTopY, _size.Width, _size.Height);
        }
    }
}
